# Maintainer: taotieren <admin@taotieren.com>

pkgbase=repo-misc-tools-git
pkgname=(
    repo-misc-tools-git
    aur-repo-mirrorlist-git
    devtools-aur-repo-git
)
pkgver=r102.c67d42d
pkgrel=1
pkgdesc="repo miscellaneous tools"
arch=(any)
url="https://github.com/taotieren/repo-misc-tools"
license=('MIT')
depends=('sh'
    #     'systemd-libs'
)
makedepends=('git')
source=("${pkgbase}::git+${url}.git")
sha256sums=('SKIP')

pkgver() {
    cd "${srcdir}/${pkgbase}"
    (
        set -o pipefail
        git describe --long --tag --abbrev=7 2>/dev/null | sed 's/^v//g;s/\([^-]*-g\)/r\1/;s/-/./g' ||
            printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short=7 HEAD)"
    )
}

prepare() {
    git -C "${srcdir}/${pkgbase}" clean -dfx
}

package_repo-misc-tools-git() {
    provides=(${pkgname%-git})
    conflicts=(${pkgname%-git})

    cd "${srcdir}/${pkgbase}/cleanup-repo-tools/"
    install -Dm0755 cleanup-repo-tool.sh "${pkgdir}/usr/bin/cleanup-repo-tool"
    install -Dm0644 -t "${pkgdir}/usr/lib/systemd/system" cleanup-repo-tool.service
    install -Dm0644 -t "${pkgdir}/usr/lib/systemd/system" cleanup-repo-tool.timer
    install -dm0755 "${pkgdir}/var/log/cleanup-repo-tool"
}

package_aur-repo-mirrorlist-git() {
    pkgdesc="Arch Linux aur-repo mirrorlist or use by pacman"
    provides=(${pkgname%-git})
    conflicts=(${pkgname%-git})
    backup=(etc/pacman.d/aur-repo-mirrorlist)

    cd "${srcdir}/${pkgbase}/mirrorlist/"

    install -Dm0644 aur-repo-mirrorlist -t "${pkgdir}/etc/pacman.d/"
    install -Dm0644 aur-repo.urls -t "${pkgdir}/etc/debuginfod/"
}

package_devtools-aur-repo-git() {
    pkgdesc="Tools for Arch Linux package maintainers - aur-repo"
    provides=(${pkgname%-git})
    conflicts=(${pkgname%-git})
    depends=(devtools)

    cd "${srcdir}/${pkgbase}/devtools-aur-repo/"

    install -Dm0755 aur-repo-x86_64-build -t "${pkgdir}/usr/bin/"
    install -Dm0644 aur-repo.conf -t "${pkgdir}/usr/share/devtools/pacman.conf.d/"
}
